<?php


use Phinx\Seed\AbstractSeed;
use App\Library\Utils\Arr;
use Faker\Factory as FakerFactory;

class AnswerLikeSeeder extends AbstractSeed
{
    public function getDependencies(): array
    {
        return [
            'AnswerSeeder',
        ];
    }

    /**
     * Run Method.
     *
     * Write your database seeder using this method.
     *
     * More information on writing seeders is available here:
     * https://book.cakephp.org/phinx/0/en/seeding.html
     */
    public function run()
    {
        $faker = FakerFactory::create('zh_CN');

        $answers = $this->fetchAll("SELECT * FROM kg_answer");
        $users = $this->fetchAll('SELECT * FROM kg_user');

        $rows = [];
        for ($i = 0; $i < 1000; $i++) {
            $rows[] = [
                'answer_id' => Arr::rand($answers)['id'],
                'user_id' => Arr::rand($users)['id'],
                'create_time' => $faker->unixTime,
                'update_time' => $faker->unixTime,
            ];
        }
        $this->table('kg_answer_like')->insert($rows)->saveData();
    }
}
